package com.zking.ssm.controller;


import com.zking.ssm.model.HotelRecharge;
import com.zking.ssm.service.IHotelRechargeService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController  //返回json格式的数据
@RequestMapping("/Con") //窄化路径
public class HotelRechargeController {

    @Autowired
    private IHotelRechargeService iHotelRechargeService;

    @RequestMapping("/list")
    public Map<String,Object> list(HotelRecharge hotelRecharge){
        PageBean pageBean = new PageBean();
        List<HotelRecharge> list = iHotelRechargeService.SelectAll(hotelRecharge, pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询充值记录成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询充值记录失败！");
        }
        return map;
    }

    @RequestMapping("/add")
    public Map<String,Object> add(HotelRecharge hotelRecharge){
        int n = iHotelRechargeService.insert(hotelRecharge);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","充值成功！");
        }else{
            map.put("code",-1);
            map.put("message","充值失败！");
        }
        return map;
    }

    @RequestMapping("/del")
    public Map<String,Object> del(HotelRecharge hotelRecharge){
        int n = iHotelRechargeService.deleteByPrimaryKey(hotelRecharge.getId());
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","删除充值记录成功！");
        }else{
            map.put("code",-1);
            map.put("message","删除充值记录失败！");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelRecharge hotelRecharge){
        int n = iHotelRechargeService.updateByPrimaryKeySelective(hotelRecharge);
        Map<String,Object> map = new HashMap<>();
        if(n > 0){
            map.put("code",0);
            map.put("message","修改充值成功！");
        }else{
            map.put("code",-1);
            map.put("message","修改充值失败！");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(HotelRecharge hotelRecharge){
        HotelRecharge user = iHotelRechargeService.selectByPrimaryKey(hotelRecharge.getId());
        Map<String,Object> map = new HashMap<>();
        if(user != null){
            map.put("code",0);
            map.put("message","查询充值成功！");
            map.put("request",user);
        }else{
            map.put("code",-1);
            map.put("message","查询充值失败！");
        }
        return map;
    }


}
